<!--
 * @Author: 田斌 tianbin0912@163.com
 * @Date: 2024-01-11 15:13:27
 * @LastEditors: 田斌 tianbin0912@163.com
 * @LastEditTime: 2024-01-12 10:05:43
 * @FilePath: \undefinedc:\Users\KT00323-5\Desktop\loca1.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }
        #container {
            width: 100%;
            height: 100vh;
            background-color: pink;
        }
    </style>
    <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
    <script>
        // init vConsole
        var vConsole = new VConsole();
        console.log('Hello world');
    </script>
    <script type="text/javascript">
      window._AMapSecurityConfig = {
        securityJsCode: "66425c4b9088233c5afa48e9d2653578",
      };
    </script>
    <script
            type="text/javascript"
            src="https://webapi.amap.com/maps?v=1.4.15&key=322d6bc61bc10f4e2a82963fca146be9"
    ></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
      //地图初始化应该在地图容器 <div> 已经添加到 DOM 树之后
      var map = new AMap.Map("container", {zoom: 12,});
      // 采用消息方式
//      var h5Port
//      window.addEventListener("message", function (event) {
//        if (event.data == "__init_port__") {
//            h5Port =  event.ports[0]
//           h5Port.postMessage(JSON.stringify({ type: 'connect_ok' })) // 告知原生连接成功
//        }
//      })

      function setZuobiao (j, w) {
        map.setZoomAndCenter(18, [j,w])
        map.plugin(["AMap.PlaceSearch"], function () {
          var MSearch = new AMap.PlaceSearch({
                 pageSize: 4,
                 pageIndex: 1, //请求页码，默认1
                 extensions: "base", //返回信息详略，默认为base（基本信息）
               }) //构造PlaceSearch类
          AMap.event.addListener(MSearch, 'error', (error) => {
                   shenling.alert('失败')
                    shenling.alert(JSON.stringify(error))
               })
          AMap.event.addListener(MSearch, "complete", (result) => {
                   shenling.alert('成功')
                   shenling.receiveData("search_list",JSON.stringify(result?.poiList?.pois || []))
               }) //返回结果
          MSearch.searchNearBy("地点", new AMap.LngLat(j, w)) //关键字查询
        });
      }

      window.onload = async function () {
        window.shenling.getLocation('setZuobiao')
      }
    </script>
</body>
</html>